﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;
namespace GSLMS.Entity
{
	/// <summary>
	/// 城市信息表
	/// </summary>
	[DataContract(IsReference = true)]
	public partial class TB_SYS_CITY: IObjectWithChangeTracker, INotifyPropertyChanged
	{
		public TB_SYS_CITY()
		{}
		#region Model
		private long _cityid;
		private string _cityname;
		private long _provinceid;
		private string _areacode;
		/// <summary>
		/// 城市记录ID
		/// </summary>
		[DataMember]
		public long CITYID
		{
			get{return _cityid;}
			set{
				if ( _cityid!= value)
				{
					if (ChangeTracker.ChangeTrackingEnabled && ChangeTracker.State != ObjectState.Added)
					{
						throw new InvalidOperationException("属性“CITYID”是对象键的一部分，不可更改。仅当未跟踪对象或对象处于“已添加”状态时，才能对键属性进行更改。");
					}
					 _cityid = value;
					OnPropertyChanged("CITYID");
				}
			}
		}
		/// <summary>
		/// 城市名称
		/// </summary>
		[DataMember]
		public string CITYNAME
		{
			get{return _cityname;}
			set{
				if ( _cityname!= value)
				{
					 _cityname = value;
					OnPropertyChanged("CITYNAME");
				}
			}
		}
		/// <summary>
		/// 省份记录ID
		/// </summary>
		[DataMember]
		public long PROVINCEID
		{
			get{return _provinceid;}
			set{
				if ( _provinceid!= value)
				{
					 _provinceid = value;
					OnPropertyChanged("PROVINCEID");
				}
			}
		}
		/// <summary>
		/// 邮政编码
		/// </summary>
		[DataMember]
		public string AREACODE
		{
			get{return _areacode;}
			set{
				if ( _areacode!= value)
				{
					 _areacode = value;
					OnPropertyChanged("AREACODE");
				}
			}
		}
		#endregion Model

	#region ChangeTracking
	   
	protected virtual void OnPropertyChanged(String propertyName)
	{
	    if (ChangeTracker.State != ObjectState.Added && ChangeTracker.State != ObjectState.Deleted)
	    {
	        ChangeTracker.State = ObjectState.Modified;
	    }
	    if (_propertyChanged != null)
	    {
	        _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
	    }
	}
	   
	protected virtual void OnNavigationPropertyChanged(String propertyName)
	{
	    if (_propertyChanged != null)
	    {
	        _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
	    }
	}
	   
	event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged{ add { _propertyChanged += value; } remove { _propertyChanged -= value; } }
	private event PropertyChangedEventHandler _propertyChanged;
	private ObjectChangeTracker _changeTracker;
	   
	[DataMember]
	public ObjectChangeTracker ChangeTracker
	{
	    get
	    {
	        if (_changeTracker == null)
	        {
	            _changeTracker = new ObjectChangeTracker();
	            _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
	        }
	        return _changeTracker;
	    }
	    set
	    {
	        if(_changeTracker != null)
	        {
	            _changeTracker.ObjectStateChanging -= HandleObjectStateChanging;
	        }
	        _changeTracker = value;
	        if(_changeTracker != null)
	        {
	            _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
	        }
	    }
	}
	   
	private void HandleObjectStateChanging(object sender, ObjectStateChangingEventArgs e)
	{
	    if (e.NewState == ObjectState.Deleted)
	    {
	        ClearNavigationProperties();
	    }
	}
	   
	protected bool IsDeserializing { get; private set; }
	   
	[OnDeserializing]
	public void OnDeserializingMethod(StreamingContext context)
	{
	    IsDeserializing = true;
	}
	   
	[OnDeserialized]
	public void OnDeserializedMethod(StreamingContext context)
	{
	    IsDeserializing = false;
	    ChangeTracker.ChangeTrackingEnabled = true;
	}
	   
	protected virtual void ClearNavigationProperties()
	{
	}
	
	#endregion

	}
}

